package com.mb.prod.controller;

import com.mb.common.pojo.Product;
import com.mb.common.vo.EasyUIResult;
import com.mb.common.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mb.prod.service.ProdService;

@RestController
@RequestMapping("/product/manage")
public class ProdController {
    //商品分页
    @Autowired(required = false)
    private ProdService service;
    @RequestMapping("/pageManage")
    public EasyUIResult QueryByPage(Integer page,Integer rows){
        return service.queryByPage(page,rows);
    }


    //根据id查询详细数据
    @RequestMapping(value = "/item/{productId}",method = RequestMethod.POST)
    public Product QueryOneProduct(@PathVariable("productId") String productId){
    //控制层调用业务层获取商品对象数据
        return service.queryOneProduct(productId);
    }

    //新增商品
    @RequestMapping("/save")
    public SysResult addProduct(Product product){
        try{
            service.addProduct(product);
            return SysResult.ok();
        }catch (Exception e){
            e.printStackTrace();
            return SysResult.build(201,"新增商品失败!!!!!!",null);
        }

    }

    //更新商品
    @RequestMapping("/update")
    public SysResult editProduct(Product product){
        try{
            service.editProduct(product);
            return SysResult.ok();
        }catch (Exception e){
            e.printStackTrace();
            return SysResult.build(201,"更新失败",null);

        }
    }




}
